clear
set more off

* -----------------------------------------------------------

use "${final}/ivr_clean_data.dta", clear
replace savings_base=savings_base/100
replace savings2_base=savings2_base/10000
drop if treatment == 0

global list 1 A1 2 3 4 5 6 6B 7 8 9 10  

foreach l in $list{
	recode Q`l'_answer (0 = 1) (1 = 0), gen(Q`l'_noanswer)
	label var Q`l'_noanswer "Q`l'"

}

global list 1 2 3 4 5 6 6B 7 8 9 10 


est clear 
foreach l in $list{
	
	eststo: reg Q`l'_noanswer female age_100 age2_10000 loan accra /*
	*/						   savings_base savings2_base missing_gender missing_age
	quietly summ Q`l'_noanswer
	estadd scalar r(mean)
}
	esttab using "${output}/attrition_baseline_long.tex", replace /*
	*/	   sfmt(%9.3fc) number booktabs f b(3) se(3) label depvars/*
	*/	   star(* 0.1 ** 0.05 *** 0.01)							/*
	*/	   keep(female age_100 age2_10000 loan savings_base savings2_base accra) /*
	*/	   order(female age loan accra)/*	
	*/	   coeflabel(female "Female" /*
	*/				 age_100 	"$\text{Age} /$ 100"/*
	*/				 age2_10000 "$\text{Age}^2 /$ 10,000"/*
	*/				 loan   "Loan Client"/*
	*/				 savings_base "Savings (100 GHS)" savings2_base "Savings (100 GHS) squared" /*
	*/	 			 accra  "Lives in Accra") /*
	*/ 	   mtitles("Q1" "Q2" "Q3" "Q4" "Q5" "Q6" "Q7"/*
	*/			   "Q8" "Q9" "Q10" "Q11" ) /*
	*/     collabels(none) compress /*
	*/	   scalars("N Observations" "F F statistic" /*
	*/			   "p p-value" "mean Mean Attrition") 

est clear
foreach l in $list{
	
	eststo: reg Q`l'_noanswer treatment_3 i.strata	
	quietly summ Q`l'_noanswer if treatment == 1
	estadd scalar r(mean)
}

	esttab using "${output}/attrition_treatment_long.tex", replace /*
	*/	   sfmt(%12.3fc) number booktabs f b(3) se(3) label depvars/*
	*/	   star(* 0.1 ** 0.05 *** 0.01)							/*
	*/	   keep(treatment_3 ) /*
	*/	   order(treatment_3 )/*	
	*/	   coeflabel(treatment_3 "Treatment" ) /*
	*/ 	   mtitles("Q1" "Q2" "Q3" "Q4" "Q5" "Q6" "Q7"/*
	*/			   "Q8" "Q9" "Q10" "Q11" ) /*
	*/     collabels(none) compress /*
	*/	   scalars("N Observations" "F F statistic" /*
	*/			   "p p-value" "mean Mean Attrition (Savings)") 




